package com.cgy.utils.base.reflect;

import java.lang.annotation.Annotation;

import javassist.CtField;
import lombok.Getter;
import lombok.Setter;

/**
 * 注解处理类
 * @author CHTK
 */
public class ReflectAnnotationHelper {


    /**
     * 获取一个类的注解,如果未获取到则获取父类
     *
     * @param clazz      要获取的类
     * @param annotation 注解类型
     * @param <T>        注解类型泛型
     * @return 注解
     */
    public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> annotation) {
        T ann = clazz.getAnnotation(annotation);
        if (ann != null) {
            return ann;
        } else {
            if (clazz.getSuperclass() != Object.class) {
                //尝试获取父类
                return getAnnotation(clazz.getSuperclass(), annotation);
            }
        }
        return ann;
    }

    /**
     * 处理 annotation
     * @param ctField
     */
    public static AnnotationInfoContent ctAnnotation(final CtField ctField) {
        //字段名

        return new AnnotationInfoContent();
    }


    @Getter
    @Setter
    public static class AnnotationInfoContent {
        private String annotationName;
        protected Class<? extends Annotation> aClass;
        protected Annotation annotation;
    }

}
